package com.zjff.myshop.util;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Data
// 分页工具类
public class PageList<T> implements Serializable {

    @ApiModelProperty(value = "总记录数", position = 1)
    private int totalCount;

    @ApiModelProperty(value = "每页记录数", position = 2)
    private int pageSize;

    @ApiModelProperty(value = "总页数", position = 3)
    private int totalPage;

    @ApiModelProperty(value = "当前页数",position = 4)
    private int currPage;

    @ApiModelProperty(value = "列表数据",position = 5)
    private List<T> list;

    /**
     * 分页
     *
     * @param list       列表数据
     * @param totalCount 总记录数
     * @param pageSize   每页记录数
     * @param currPage   当前页数
     */
    public PageList(List<T> list, int totalCount, int pageSize, int currPage) {
        this.list = list;
        this.totalCount = totalCount;
        this.pageSize = pageSize;
        this.currPage = currPage;
        this.totalPage = (int) Math.ceil((double) totalCount / pageSize);
    }

}
